<h2>test-form onsubmit</h2>
<!-- HTML -->
<form id="test-form" onsubmit="return checkForm()">
    <input type="text" name="test">
    <button type="submit">Submit</button>
</form>
<!-- 浏览器默认点击<button type="submit">时提交表单 -->
<script>
function checkForm() {
    var form = document.getElementById('test-form');
    // 可以在此修改form的input...
    // 继续下一步:
    return true;
}
</script>

<h2>login-form post secure</h2>
<form id="login-form" method="post" onsubmit="return checkFormS()">
    <input type="text" id="username" name="username">
    <input type="password" id="password" name="password">
    <button type="submit">Submit</button>
</form>

<script>
function checkFormS() {
    var pwd = document.getElementById('password');
    pwd.value = toMD5(pwd.value);
    return true;
}
</script>

<h2>login-form post more secure</h2>
<form id="login-form" method="post" onsubmit="return checkFormSS()">
    <input type="text" id="username" name="username">
    <input type="password" id="input-password">
    <input type="hidden" id="md5-password" name="password">
    <button type="submit">Submit</button>
</form>

<script>
function checkFormSS() {
    var input_pwd = document.getElementById('input-password');
    var md5_pwd = document.getElementById('md5-password');
    // 把用户输入的明文变为MD5:
    md5_pwd.value = toMD5(input_pwd.value);
    // 继续下一步:
    return true;
}
</script>